#include<vector>
using namespace std;
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
    vector<int>res;

    int front=0,tail=nums.size()-1;
    while(front<tail)
    {
        if(nums[front]+nums[tail]>target)
        {
            tail--;
        }
        else if(nums[front]+nums[tail]<target)
        {
            front++;
        }
        else{
            res.push_back(nums[front]);
            res.push_back(nums[tail]);
            break;
        }
    }
    return res;
    }
};